﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using log4net;

namespace DAL
{
    public class Product
    {
        private static ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public List<IMG> IMGs { get; set; }

        public List<string> ToCsv(String sourceImgDir,String targetImgDir,String relative)
        {
            if (IMGs == null || IMGs.Count == 0)
                return null;
            List<String> list = new List<string>();
            foreach (IMG img in IMGs)
            {
                list.Add(img.ToCsv(relative));

                //copy img
                if (!String.IsNullOrEmpty(img.imgName1))
                {
                    String source = sourceImgDir + "\\" + img.id + ".jpg";
                    String target = targetImgDir + "\\" + img.imgName1;
                    try
                    {
                        File.Copy(source, target, true);
                    }
                    catch (Exception e)
                    {
                        log.Info(e.Message);
                    }
                }
            }
            return list;
        }
    }
}
